package com.aaa.mbs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.entity.AccountStatement;
import com.aaa.mbs.service.AccountStatementService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (AccountStatement)表控制层
 *
 * @author makejava
 * @since 2020-12-05 14:29:31
 */
@RestController
@RequestMapping("accountStatement")
public class AccountStatementController {
    /**
     * 服务对象
     */
    @Resource
    private AccountStatementService accountStatementService;

    /**
     * 收入记录统计
     * @param yearMonth
     * @return
     */
    @GetMapping("incomeRecord")
    public Result incomeRecordTotal(@RequestParam("yearMonth") String yearMonth) {
        return accountStatementService.incomeRecordTotal(yearMonth);
    }
    /**
     * 进行充值
     * @param accountStatement
     * @return
     */
    @PostMapping("addMoney")
    public Result addMoney(@RequestBody AccountStatement accountStatement) {
        return accountStatementService.addToBalance(accountStatement);
    }

    /**
     * 通过客户id查询相关明细信息
     * @return
     */
    @GetMapping("selectByClientId")
    public Result selectByClientId(Integer clientId) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), accountStatementService.selectByClientId (clientId));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public AccountStatement selectOne(Integer id) {
        return this.accountStatementService.queryById(id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo           第几页
     * @param pageSize         每页显示数量
     * @param accountStatement 实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody AccountStatement accountStatement) {
        return this.accountStatementService.queryAll(pageNo, pageSize, accountStatement);
    }

    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.accountStatementService.deleteById(id));
    }

    /**
     * 更新
     *
     * @param @param accountStatement 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody AccountStatement accountStatement) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.accountStatementService.update(accountStatement));
    }

    /**
     * 添加
     *
     * @param @param accountStatement 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody AccountStatement accountStatement) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.accountStatementService.insert(accountStatement));
    }
}